/**
 * 
 */
package com.toncen.samepms.util;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.toncen.samepms.system.dao.SchedulerJobDao;
import com.sky.common.quartz.QuartzManager;

/**
 * 描述：应用监听器
 * 
 * @author tch
 * 
 */
public class ApplicationListner implements ServletContextListener {
	protected static Log logger = LogFactory.getLog(ApplicationListner.class);

	public ApplicationListner() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	public void contextDestroyed(ServletContextEvent arg0) {
		try {
			logger.info("开始停止计划任务...");
			QuartzManager.shutdown();
			logger.info("成功停止计划任务...");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("停止计划任务失败：" + e.getMessage());
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	public void contextInitialized(ServletContextEvent arg0) {
		SchedulerJobDao schedulerJobDao = new SchedulerJobDao();
		try {
			schedulerJobDao.restartScheduler();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("启动计划任务失败：" + e.getMessage());
		}
	}
}
